﻿namespace MDXStudio
{
    using MDXStudio.MdSchema;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using WeifenLuo.WinFormsUI.Docking;

    public class MetadataWindow : DockContent
    {
        private IContainer components;
        private ImageList imageListMetadata;
        private MdTreeBuilder mTreeBuilder;
        private TreeView treeViewMetadata;

        public MetadataWindow()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(MetadataWindow));
            this.treeViewMetadata = new TreeView();
            this.imageListMetadata = new ImageList(this.components);
            base.SuspendLayout();
            this.treeViewMetadata.AllowDrop = true;
            this.treeViewMetadata.Dock = DockStyle.Fill;
            this.treeViewMetadata.HideSelection = false;
            this.treeViewMetadata.ImageIndex = 0;
            this.treeViewMetadata.ImageList = this.imageListMetadata;
            this.treeViewMetadata.Location = new Point(0, 0);
            this.treeViewMetadata.Name = "treeViewMetadata";
            this.treeViewMetadata.SelectedImageIndex = 0;
            this.treeViewMetadata.Size = new Size(0x124, 0x111);
            this.treeViewMetadata.TabIndex = 1;
            this.treeViewMetadata.BeforeExpand += new TreeViewCancelEventHandler(this.treeViewMetadata_BeforeExpand);
            this.treeViewMetadata.DragEnter += new DragEventHandler(this.treeViewMetadata_DragEnter);
            this.treeViewMetadata.ItemDrag += new ItemDragEventHandler(this.treeViewMetadata_ItemDrag);
            this.imageListMetadata.ImageStream = (ImageListStreamer) manager.GetObject("imageListMetadata.ImageStream");
            this.imageListMetadata.TransparentColor = Color.Transparent;
            this.imageListMetadata.Images.SetKeyName(0, "Cube.ico");
            this.imageListMetadata.Images.SetKeyName(1, "Dimension.ico");
            this.imageListMetadata.Images.SetKeyName(2, "Measure.ico");
            this.imageListMetadata.Images.SetKeyName(3, "MeasureCalculated.ico");
            this.imageListMetadata.Images.SetKeyName(4, "Kpi.ico");
            this.imageListMetadata.Images.SetKeyName(5, "FolderOpen.ico");
            this.imageListMetadata.Images.SetKeyName(6, "FolderClosed.ico");
            this.imageListMetadata.Images.SetKeyName(7, "Hierarchy.ico");
            this.imageListMetadata.Images.SetKeyName(8, "ParentChild.ico");
            this.imageListMetadata.Images.SetKeyName(9, "AttributeHierarchy.ico");
            this.imageListMetadata.Images.SetKeyName(10, "Level1.ico");
            this.imageListMetadata.Images.SetKeyName(11, "Level2.ico");
            this.imageListMetadata.Images.SetKeyName(12, "Level3.ico");
            this.imageListMetadata.Images.SetKeyName(13, "Level4.ico");
            this.imageListMetadata.Images.SetKeyName(14, "Level5.ico");
            this.imageListMetadata.Images.SetKeyName(15, "Level6.ico");
            this.imageListMetadata.Images.SetKeyName(0x10, "Level7.ico");
            this.imageListMetadata.Images.SetKeyName(0x11, "Level8.ico");
            this.imageListMetadata.Images.SetKeyName(0x12, "Level9.ico");
            this.imageListMetadata.Images.SetKeyName(0x13, "Level10.ico");
            this.imageListMetadata.Images.SetKeyName(20, "Level11.ico");
            this.imageListMetadata.Images.SetKeyName(0x15, "Level12.ico");
            this.imageListMetadata.Images.SetKeyName(0x16, "Level13.ico");
            this.imageListMetadata.Images.SetKeyName(0x17, "Level14.ico");
            this.imageListMetadata.Images.SetKeyName(0x18, "Level15.ico");
            this.imageListMetadata.Images.SetKeyName(0x19, "Level16.ico");
            this.imageListMetadata.Images.SetKeyName(0x1a, "NamedSet.ico");
            this.imageListMetadata.Images.SetKeyName(0x1b, "MDXQuery.ico");
            this.imageListMetadata.Images.SetKeyName(0x1c, "AttributeKey.ico");
            this.imageListMetadata.Images.SetKeyName(0x1d, "Member.ico");
            this.imageListMetadata.Images.SetKeyName(30, "ParentChildDisabled.ico");
            this.imageListMetadata.Images.SetKeyName(0x1f, "AttributeKeyDisabled.ico");
            this.imageListMetadata.Images.SetKeyName(0x20, "AttributeWithDisabledHierarchy.ico");
            this.imageListMetadata.Images.SetKeyName(0x21, "Script.ico");
            this.imageListMetadata.Images.SetKeyName(0x22, "CellCalculation.ico");
            this.imageListMetadata.Images.SetKeyName(0x23, "Scope.ico");
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x124, 0x111);
            base.Controls.Add(this.treeViewMetadata);
            base.HideOnClose = true;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "MetadataWindow";
            base.TabText = "Metadata";
            this.Text = "Metadata";
            base.Load += new EventHandler(this.MetadataWindow_Load);
            base.ResumeLayout(false);
        }

        private void MetadataWindow_Load(object sender, EventArgs e)
        {
            this.mTreeBuilder = new MdTreeBuilder();
            this.mTreeBuilder.MaxMemberCount = 100;
            this.mTreeBuilder.ShowHiddenObjects = true;
        }

        private void treeViewMetadata_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            this.treeViewMetadata.SuspendLayout();
            this.mTreeBuilder.ExpandNode(e.Node);
            this.treeViewMetadata.ResumeLayout();
        }

        private void treeViewMetadata_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Move;
        }

        private void treeViewMetadata_ItemDrag(object sender, ItemDragEventArgs e)
        {
            base.DoDragDrop(((TreeNode) e.Item).Name, DragDropEffects.Move);
        }

        internal MdTreeBuilder TreeBuilder
        {
            get
            {
                return this.mTreeBuilder;
            }
        }

        internal TreeView TreeViewMetadata
        {
            get
            {
                return this.treeViewMetadata;
            }
        }
    }
}

